#include <iostream>
#include <memory>

#include "serialization.hpp"
#include "Sock.hpp"
#include "TcpServer.hpp"
#include "calculator.hpp"

void Usage()
{
    std::cout << "using warning, Please enter: " << std::endl;
    std::cout << "[./server ip port] or [./server port]" << std::endl;
}

// ./server.cc 8080
int main(int argc, char* argv[])
{
    if (argc != 2 && argc != 3)
    {
        Usage();
        return 10;
    }

    std::string ip = argc == 2 ? "" : argv[1];
    uint16_t port = argc == 2 ? atoi(argv[1]) : atoi(argv[2]);

    std::unique_ptr<TcpServer> tcp(new TcpServer(port, ip));
    tcp->InitServer();
    tcp->BindServer(Calculator);
    tcp->StartServer();

    return 0;
}